package com.zmn.plat.admin.controller.channel.cityratio;

import java.util.*;
import java.util.stream.Collectors;

import com.zmn.plat.common.constant.ProductConsts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.DictModel;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.common.constant.BaseAreaConsts;
import com.zmn.plat.common.dictionary.ChannelCityRatioTypeEnum;
import com.zmn.plat.manager.dictionary.StatusEnum;
import com.zmn.plat.model.entity.area.AreaQuery;
import com.zmn.plat.model.entity.area.BaseArea;
import com.zmn.plat.model.entity.category.BaseCategory;
import com.zmn.plat.model.entity.channel.Channel;
import com.zmn.plat.model.entity.channel.ChannelCityPriceRatio;
import com.zmn.plat.model.entity.channel.ChannelCityPriceRatioQuery;
import com.zmn.plat.model.entity.servcategory.ServCategory;
import com.zmn.plat.model.vo.channel.ChannelCityPriceRatioVo;

/**
 * 类描述:渠道城市价格系数管理查询控制
 *
 * @author linfeng
 * @since 2019/08/27/11:02
 */
@Controller
@RequestMapping("/channel/citypriceratio/")
public class ChannelCityPriceRatioListController extends ChannelCityPriceRatioBaseController {
    private Logger logger = LoggerFactory.getLogger(ChannelCityPriceRatioListController.class);

    /**
     * 描述: 渠道城市价格系数列表
     *
     * @param query 查询实体
     * @return ModelAndView
     */
    @RequestMapping(value = "list")
    public ModelAndView list(@ModelAttribute ChannelCityPriceRatioQuery query, @RequestParam(value = "channelId") Integer channelId,
                             String addFlag, Integer bizType) {
        ModelAndView mav = new ModelAndView("channel/citypriceratio/list");

        if (query.getRatioType() == null) {
            query.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYRATIO.getCode());
        }

        try {
            query.setChannelId(0);
            if (NumberUtil.isNotNullOrZero(channelId)) {
                query.setChannelId(channelId);
            }
            if (bizType == ProductConsts.BIZ_TYPE_C) {
                // C类业务价格系数返回计价器3.0默认系数
                query.setMeterQuery(Boolean.TRUE);
            }
            Channel obj = channelService.findByKey(channelId);
            List<DictModel> provinces = areaCache.getAreaList(GlobalConsts.TOP_ID);
            List<ChannelCityPriceRatioVo> items = channelCityPriceRatioService.listPageByQuery(query);
            if (query.getPageIndex() == GlobalConsts.NO) {
                ChannelCityPriceRatioQuery channelCityPriceRatioQuery = new ChannelCityPriceRatioQuery();
                channelCityPriceRatioQuery.setChannelId(channelId);
                channelCityPriceRatioQuery.setBizType(bizType);
                channelCityPriceRatioQuery.setPriceType(query.getPriceType());
                channelCityPriceRatioQuery.setRatioType(ChannelCityRatioTypeEnum.CHANNELRATIO.getCode());
                ChannelCityPriceRatio channelCityPriceRatio =
                        channelCityPriceRatioService.findByChannelIdAndCityAndCategAndType(channelCityPriceRatioQuery);
                ChannelCityPriceRatioVo entireCountry = new ChannelCityPriceRatioVo() {
                    {
                        setName("全国");
                        if (channelCityPriceRatio != null) {
                            setRatio(channelCityPriceRatio.getRatio());
                            setToBeEffectiveRatio(channelCityPriceRatio.getToBeEffectiveRatio());

                            setUpdater(channelCityPriceRatio.getUpdater());
                            setUpdateTime(channelCityPriceRatio.getUpdateTime());
                        }
                    }
                };
                if (bizType == ProductConsts.BIZ_TYPE_C) {
                    channelCityPriceRatioQuery.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYMETER3RATIO.getCode());
                    ChannelCityPriceRatio channelCityPriceRatioMeter =
                            channelCityPriceRatioService.findByChannelIdAndCityAndCategAndType(channelCityPriceRatioQuery);
                    if (!Objects.isNull(channelCityPriceRatioMeter)) {
                        entireCountry.setMeterRatio(channelCityPriceRatioMeter.getRatio());
                        entireCountry.setMeterToBeEffectiveRatio(channelCityPriceRatioMeter.getToBeEffectiveRatio());
                    }
                }
                items.add(0, entireCountry);
            }
            mav.addObject("obj", obj);
            mav.addObject("flag", 5);
            mav.addObject("addFlag", addFlag);
            mav.addObject("bizType", bizType);
            mav.addObject("priceType", query.getPriceType());
            mav.addObject("vo", query);
            mav.addObject("provinces", provinces);
            mav.addObject("channelId", channelId);
            mav.addObject("items", items);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return mav;
    }

    /**
     * 渠道城市分类系数(城市一二级分类系数表)
     *
     * @param channelId
     * @param cityId
     * @param provinceId
     * @param servCategId
     * @param cityName
     * @param bizType     1保外 2保内 3工程
     * @return
     */
    @RequestMapping(value = "categoryRatio")
    @SuppressWarnings("Duplicates")
    public ModelAndView categoryRatio(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                      @RequestParam(value = "cityId", defaultValue = "0") Integer cityId,
                                      @RequestParam(value = "provinceId", defaultValue = "0") Integer provinceId,
                                      @RequestParam(value = "servCategId", defaultValue = "0") Integer servCategId,
                                      @RequestParam(value = "cityName", defaultValue = "") String cityName,
                                      @RequestParam(value = "addFlag", defaultValue = "") String addFlag,
                                      @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                                      @RequestParam(value = "priceType", defaultValue = "1") Integer priceType) {
        ChannelCityPriceRatioQuery query = new ChannelCityPriceRatioQuery();
        query.setChannelId(channelId);
        query.setCityId(cityId);
        query.setProvinceId(provinceId);
        query.setServCategId(servCategId);
        query.setBizType(bizType);
        query.setPriceType(priceType);

        Channel obj = channelService.findByKey(channelId);
        ServCategory servCategoryQuery = new ServCategory();
        servCategoryQuery.setStatus(StatusEnum.ENABLE.getCode());
        List<ServCategory> servCategoryList = servCategoryService.listByQuery(servCategoryQuery);
        String servCategName = "";
        if (servCategId == 0) {
            if (servCategoryList != null && servCategoryList.size() > 0) {
                ServCategory servCategory = servCategoryList.get(0);
                query.setServCategId(servCategory.getCategId());
                servCategName = servCategory.getName();
            }
        } else {
            ServCategory servCategory = servCategoryService.findByKey(servCategId);
            servCategName = servCategory.getName();
        }

        query.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYCATEGONERATIO.getCode());
        List<ChannelCityPriceRatio> channelCityPriceLevelOneRatioVos = channelCityPriceRatioService.listByQuery(query);
        query.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYCATEGTWORATIO.getCode());
        List<ChannelCityPriceRatio> channelCityPriceLevelTwoRatioVos = channelCityPriceRatioService.listByQuery(query);

        List<BaseCategory> categTwos = servAssCategoryService.findCategoryTwoByServId(query.getServCategId());
        Map<Integer, List<BaseCategory>> map = categTwos.stream().collect(Collectors.groupingBy(BaseCategory::getParentId));
        Map<Integer, List<ChannelCityPriceRatioVo>> levelTwoRatioMap = new HashMap<>();
        for (Map.Entry<Integer, List<BaseCategory>> entry : map.entrySet()) {
            List<ChannelCityPriceRatioVo> resultList = new ArrayList<>();
            if (entry.getValue() != null) {
                for (BaseCategory baseCategory : entry.getValue()) {
                    ChannelCityPriceRatioVo channelCityPriceLevelTwoRatioVo = new ChannelCityPriceRatioVo();
                    channelCityPriceLevelTwoRatioVo.setCityId(cityId);
                    channelCityPriceLevelTwoRatioVo.setProvinceId(provinceId);
                    channelCityPriceLevelTwoRatioVo.setCategOneId(entry.getKey());
                    channelCityPriceLevelTwoRatioVo.setCategId(baseCategory.getCategId());
                    channelCityPriceLevelTwoRatioVo.setCategName(baseCategory.getName());
                    for (ChannelCityPriceRatio inner : channelCityPriceLevelTwoRatioVos) {
                        if (inner.getCategId().equals(baseCategory.getCategId())
                                && inner.getCategOneId().equals(baseCategory.getParentId())) {
                            channelCityPriceLevelTwoRatioVo.setRatio(inner.getRatio());
                            channelCityPriceLevelTwoRatioVo.setToBeEffectiveRatio(inner.getToBeEffectiveRatio());
                        }
                    }
                    resultList.add(channelCityPriceLevelTwoRatioVo);
                }
            }
            levelTwoRatioMap.put(entry.getKey(), resultList);
        }

        List<BaseCategory> categOnes = servAssCategoryService.findCategoryOneByServId(query.getServCategId());
        List<ChannelCityPriceRatioVo> constructVo = new ArrayList<>();
        for (BaseCategory baseCategory : categOnes) {
            ChannelCityPriceRatioVo channelCityPriceLevelOneRatioVo = new ChannelCityPriceRatioVo();
            channelCityPriceLevelOneRatioVo.setCategOneId(baseCategory.getCategId());
            channelCityPriceLevelOneRatioVo.setCategName(baseCategory.getName());
            constructVo.add(channelCityPriceLevelOneRatioVo);
        }

        for (ChannelCityPriceRatioVo channelCityPriceLevelOneRatioVo : constructVo) {
            for (ChannelCityPriceRatio inner : channelCityPriceLevelOneRatioVos) {
                if (channelCityPriceLevelOneRatioVo.getCategOneId().equals(inner.getCategOneId())) {
                    channelCityPriceLevelOneRatioVo.setToBeEffectiveRatio(inner.getToBeEffectiveRatio());
                    channelCityPriceLevelOneRatioVo.setRatio(inner.getRatio());
                }
            }
        }

        ModelAndView mav = new ModelAndView("channel/citypriceratio/citycategoryratio");
        mav.addObject("servCategId", query.getServCategId());
        mav.addObject("channelId", query.getChannelId());
        mav.addObject("cityId", cityId);
        mav.addObject("obj", obj);
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);
        mav.addObject("provinceId", provinceId);
        mav.addObject("cityName", cityName);
        mav.addObject("servCategName", servCategName);
        mav.addObject("categOnes", constructVo);
        mav.addObject("servCategoryList", servCategoryList);
        mav.addObject("map", levelTwoRatioMap);
        mav.addObject("addFlag", addFlag);
        return mav;
    }

    /**
     * 设置渠道分类系数详情页面
     *
     * @param channelId
     * @param cityId
     * @param provinceId
     * @param servCategId
     * @param categOneId
     * @param categOneName
     * @param bizType       1保外 2保内 3工程
     * @param cityName
     * @param servCategName
     * @return
     */
    @RequestMapping(value = "detail")
    public ModelAndView detail(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                               @RequestParam(value = "cityId", defaultValue = "0") Integer cityId,
                               @RequestParam(value = "provinceId", defaultValue = "0") Integer provinceId,
                               @RequestParam(value = "servCategId", defaultValue = "0") Integer servCategId,
                               @RequestParam(value = "categOneId", defaultValue = "0") Integer categOneId,
                               @RequestParam(value = "categOneName", defaultValue = "0") String categOneName,
                               @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                               @RequestParam(value = "priceType", defaultValue = "1") Integer priceType,
                               @RequestParam(value = "cityName", defaultValue = "") String cityName,
                               @RequestParam(value = "servCategName", defaultValue = "") String servCategName, String addFlag) {
        ChannelCityPriceRatioQuery query = new ChannelCityPriceRatioQuery();
        query.setChannelId(channelId);
        query.setCityId(cityId);
        query.setProvinceId(provinceId);
        query.setServCategId(servCategId);
        query.setBizType(bizType);
        query.setPriceType(priceType);
        query.setCategOneId(categOneId);

        if (servCategId == 0) {
            ServCategory servCategory = servCategoryService.findFirstOneByCategIdAsc();
            query.setServCategId(servCategory.getCategId());
        }

        Channel obj = channelService.findByKey(channelId);
        String categOneValue = "";
        String categOneToBeEffectiveValue = "";
        query.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYCATEGONERATIO.getCode());
        ChannelCityPriceRatio channelCityPriceRatio = channelCityPriceRatioService.findByChannelIdAndCityAndCategAndType(query);

        if (channelCityPriceRatio != null) {
            categOneValue = channelCityPriceRatio.getRatio() == null ? "" : channelCityPriceRatio.getRatio().toString();
            categOneToBeEffectiveValue =
                    channelCityPriceRatio.getToBeEffectiveRatio() == null ? "" : channelCityPriceRatio.getToBeEffectiveRatio().toString();
        }

        query.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYCATEGTWORATIO.getCode());
        List<ChannelCityPriceRatio> channelCityPriceLevelTwoRatioVos = channelCityPriceRatioService.listByQuery(query);
        List<BaseCategory> categTwos = servAssCategoryService.findCategoryTwoByServId(query.getServCategId());
        Map<Integer, List<BaseCategory>> map = categTwos.stream().collect(Collectors.groupingBy(BaseCategory::getParentId));

        List<ChannelCityPriceRatioVo> resultList = new ArrayList<>();
        if (map.get(categOneId) != null) {
            for (BaseCategory baseCategory : map.get(categOneId)) {
                ChannelCityPriceRatioVo channelCityPriceLevelTwoRatioVo = new ChannelCityPriceRatioVo();
                channelCityPriceLevelTwoRatioVo.setCityId(cityId);
                channelCityPriceLevelTwoRatioVo.setProvinceId(provinceId);
                channelCityPriceLevelTwoRatioVo.setCategOneId(categOneId);
                channelCityPriceLevelTwoRatioVo.setCategId(baseCategory.getCategId());
                channelCityPriceLevelTwoRatioVo.setCategName(baseCategory.getName());
                for (ChannelCityPriceRatio inner : channelCityPriceLevelTwoRatioVos) {
                    if (inner.getCategId().equals(baseCategory.getCategId()) && inner.getCategOneId().equals(baseCategory.getParentId())) {
                        channelCityPriceLevelTwoRatioVo.setRatio(inner.getRatio());
                        channelCityPriceLevelTwoRatioVo.setToBeEffectiveRatio(inner.getToBeEffectiveRatio());
                    }
                }
                resultList.add(channelCityPriceLevelTwoRatioVo);
            }
        }

        ModelAndView mav = new ModelAndView("channel/citypriceratio/citycategoryratiodetail");
        mav.addObject("servCategId", servCategId);
        mav.addObject("channelId", channelId);
        mav.addObject("cityId", cityId);
        mav.addObject("obj", obj);
        mav.addObject("cityName", cityName);
        mav.addObject("provinceId", provinceId);
        mav.addObject("categOneId", categOneId);
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);
        mav.addObject("categOneName", categOneName);
        mav.addObject("categOneValue", categOneValue);
        mav.addObject("categOneToBeEffectiveValue", categOneToBeEffectiveValue);
        mav.addObject("servCategName", servCategName);
        mav.addObject("levelTwoRatio", resultList);
        mav.addObject("addFlag", addFlag);
        return mav;
    }

    /**
     * 渠道城市默认保内系数
     *
     * @param channelId
     * @param cityId
     * @param provinceId
     * @param bizType    1保外 2保内 3工程
     * @param priceType  1销售价 2内部价
     * @return
     */
    @RequestMapping("cityRatio")
    public ModelAndView cityRatio(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                  @RequestParam(value = "cityId", defaultValue = "0") Integer cityId,
                                  @RequestParam(value = "provinceId", defaultValue = "0") Integer provinceId,
                                  @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                                  @RequestParam(value = "priceType", defaultValue = "1") Integer priceType) {
        ChannelCityPriceRatioQuery channelCityPriceRatioQuery = new ChannelCityPriceRatioQuery();
        channelCityPriceRatioQuery.setChannelId(channelId);
        channelCityPriceRatioQuery.setPriceType(priceType);
        channelCityPriceRatioQuery.setBizType(bizType);
        channelCityPriceRatioQuery.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYRATIO.getCode());
        channelCityPriceRatioQuery.setCityId(cityId);
        ChannelCityPriceRatio channelCityPriceRatio =
                Optional.ofNullable(channelCityPriceRatioService.findByChannelIdAndCityAndCategAndType(channelCityPriceRatioQuery))
                        .orElse(new ChannelCityPriceRatio());

        BaseArea baseArea = areaCache.getArea(cityId);

        ModelAndView mav = new ModelAndView("channel/citypriceratio/setcityratio");
        if (bizType == ProductConsts.BIZ_TYPE_C) {
            // C类业务价格系数返回计价器3.0默认系数
            channelCityPriceRatioQuery.setBizType(null);
            channelCityPriceRatioQuery.setRatioType(ChannelCityRatioTypeEnum.CHANNELCITYMETER3RATIO.getCode());
            ChannelCityPriceRatio channelCityPriceRatioM =
                    Optional.ofNullable(channelCityPriceRatioService.findByChannelIdAndCityAndCategAndType(channelCityPriceRatioQuery))
                            .orElse(new ChannelCityPriceRatio());

            mav.addObject("meterRatio", channelCityPriceRatioM.getToBeEffectiveRatio() == null ? channelCityPriceRatioM.getRatio() : channelCityPriceRatioM.getToBeEffectiveRatio());
        }
        mav.addObject("cityRatio", channelCityPriceRatio);
        mav.addObject("cityId", cityId);
        mav.addObject("provinceId", provinceId);
        mav.addObject("channelId", channelId);
        mav.addObject("cityName", baseArea == null ? "" : baseArea.getName());
        mav.addObject("priceType", priceType);
        mav.addObject("bizType", bizType);
        return mav;
    }

    /**
     * 渠道城市系数快速设置,跳转到保内/保外/工程默认设置页面
     *
     * @param channelId
     * @param bizType
     * @param priceType
     * @return
     */
    @RequestMapping("cityBatchRatio")
    public ModelAndView cityBatchRatio(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                       @RequestParam(value = "bizType", defaultValue = "0") Integer bizType,
                                       @RequestParam(value = "priceType", defaultValue = "0") Integer priceType) {
        ModelAndView mav = new ModelAndView("channel/citypriceratio/batch/setcitybatchratio");
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);
        mav.addObject("channelId", channelId);
        return mav;
    }

    /**
     * 渠道城市系数快速设置,跳转到城市选择页面
     *
     * @return
     */
    @RequestMapping("citySelectBatch")
    public ModelAndView citySelectBatch(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                        @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                                        @RequestParam(value = "priceType", defaultValue = "1") Integer priceType) {
        ModelAndView mav = new ModelAndView("channel/citypriceratio/batch/_cityRatioBatch");
        // 1.加载 省--》城市
        List<BaseArea> provinces = baseAreaService.listByParentId(GlobalConsts.TOP_ID);
        // 加载城市
        AreaQuery cityQuery = new AreaQuery();
        cityQuery.setLevel(BaseAreaConsts.AREA_LEVEL_THREE);
        List<BaseArea> citys = baseAreaService.listByQuery(cityQuery);
        Map<Integer, List<BaseArea>> cityMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(citys)) {
            cityMap = citys.stream().collect(Collectors.groupingBy(BaseArea::getParentId));
        }

        Channel obj = channelService.findByKey(channelId);

        mav.addObject("provinces", provinces);
        mav.addObject("cityMap", cityMap);
        mav.addObject("channelId", channelId);
        mav.addObject("obj", obj);
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);

        return mav;
    }

    /**
     * 城市批量设置分类系数(一二级保外分类系数对应表)
     *
     * @param cityIdStr   城市ID组合成的字符串
     * @param channelId   渠道ID
     * @param bizType     业务类型
     * @param priceType   价格类型
     * @param servCategId 服务分类ID
     * @return
     */
    @RequestMapping(value = "categoryRatioBatch")
    public ModelAndView categoryRatioBatch(@RequestParam(value = "cityIdStr", defaultValue = "") String cityIdStr,
                                           @RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                           @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                                           @RequestParam(value = "priceType", defaultValue = "1") Integer priceType,
                                           @RequestParam(value = "servCategId", defaultValue = "0") Integer servCategId) {
        ModelAndView mav = new ModelAndView("channel/citypriceratio/batch/citybatchcategoryratio");
        ServCategory servCategoryQuery = new ServCategory();
        servCategoryQuery.setStatus(GlobalConsts.YES);
        List<ServCategory> servCategoryList = servCategoryService.listByQuery(servCategoryQuery);
        String servCategName = "";

        if (NumberUtil.isNullOrZero(servCategId)) {
            if (servCategoryList != null && servCategoryList.size() > 0) {
                ServCategory servCategory = servCategoryList.get(0);
                servCategId = servCategory.getCategId();
                servCategName = servCategory.getName();
            }
        } else {
            ServCategory servCategory = servCategoryService.findByKey(servCategId);
            servCategName = servCategory.getName();
        }

        List<BaseCategory> categTwos = servAssCategoryService.findCategoryTwoByServId(servCategId);
        Map<Integer, List<BaseCategory>> map = categTwos.stream().collect(Collectors.groupingBy(BaseCategory::getParentId));

        List<BaseCategory> categOnes = servAssCategoryService.findCategoryOneByServId(servCategId);
        Channel obj = channelService.findByKey(channelId);

        mav.addObject("map", map);
        mav.addObject("categOnes", categOnes);
        mav.addObject("channelId", channelId);
        mav.addObject("obj", obj);
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);
        mav.addObject("cityIdStr", cityIdStr);
        mav.addObject("servCategId", servCategId);
        mav.addObject("servCategName", servCategName);
        mav.addObject("servCategoryList", servCategoryList);
        return mav;
    }

    /**
     * 设置保内/保外分类系数的详情页面
     *
     * @param cityIdStr     城市ID集合
     * @param servCategId   服务分类ID
     * @param categOneId    一级产品分类ID
     * @param categOneName  一级产品分类名称
     * @param bizType       保内或保外或工程业务
     * @param priceType     价格类型：1 销售价 2 内部价
     * @param servCategName 服务分类名称
     * @return
     */
    @RequestMapping(value = "toCategCityRatioBatch")
    @SuppressWarnings("Duplicates")
    public ModelAndView toCategCityRatioBatch(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
                                              @RequestParam(value = "cityIdStr", defaultValue = "") String cityIdStr,
                                              @RequestParam(value = "servCategId", defaultValue = "0") int servCategId,
                                              @RequestParam(value = "categOneId", defaultValue = "0") int categOneId,
                                              @RequestParam(value = "categOneName", defaultValue = "0") String categOneName,
                                              @RequestParam(value = "bizType", defaultValue = "1") Integer bizType,
                                              @RequestParam(value = "priceType", defaultValue = "1") Integer priceType,
                                              @RequestParam(value = "servCategName", defaultValue = "") String servCategName) {

        if (servCategId == 0) {
            ServCategory servCategory = servCategoryService.findFirstOneByCategIdAsc();
            servCategId = servCategory.getCategId();
        }

        List<BaseCategory> categTwos = servAssCategoryService.findCategoryTwoByServId(servCategId);
        Map<Integer, List<BaseCategory>> map = categTwos.stream().collect(Collectors.groupingBy(BaseCategory::getParentId));
        Channel obj = channelService.findByKey(channelId);

        ModelAndView mav = new ModelAndView("channel/citypriceratio/batch/citybatchcategoryratiodetail");

        mav.addObject("servCategId", servCategId);
        mav.addObject("cityIdStr", cityIdStr);
        mav.addObject("categOneId", categOneId);
        mav.addObject("categTwos", map.get(categOneId));
        mav.addObject("channelId", channelId);
        mav.addObject("obj", obj);
        mav.addObject("bizType", bizType);
        mav.addObject("priceType", priceType);
        mav.addObject("categOneName", categOneName);
        mav.addObject("servCategName", servCategName);
        return mav;
    }

}
